<template>
	<view>
		<view class="header">皮肤类型</view>
		<view class="content">
			<radio-group @change="bindSkin" class="list">
				<label class="list_center">
					<radio value="干性" :checked="info.name == '干性'" />
					<view>干性</view>
				</label>
				<label class="list_center">
					<radio value="混合型" :checked="info.name == '混合型'" />
					<view>混合型</view>
				</label>
				<label class="list_center">
					<radio value="油性" :checked="info.name == '油性'" />
					<view>油性</view>
				</label>
				<label class="list_center">
					<radio value="过敏性" :checked="info.name == '过敏性'" />
					<view>过敏性</view>
				</label>
			</radio-group>
		</view>
		<button @click="addSkin" class="buttonClass">提交</button>
	</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	data() {
		return {
			customer_id:0,
			info:{
				name:''
			},
			name:''
		}
	},
	onLoad:function(e){
		this.member_id = e.id
		this.getSkinInfo()
	},
	methods: {
		getSkinInfo:function(){
			var data = {member_id:this.member_id}
			var that = this
			request({
				url: 'manage/skin/type',
				method: 'get',
				data:data,
				success: (res) => {
					if(res.data.data){
						that.info = res.data.data
					}
				},
			})
		},
		bindSkin:function(e){
			this.name = e.detail.value
		},
		addSkin:function(){
			var data = {
				name:this.name,
				oa_id:uni.getStorageSync('oa_id'),
				user_id:uni.getStorageSync('uid'),
				member_id:this.member_id
			}
			if(this.info){
				data.id = this.info.id
			}
			var that = this
			var pages = getCurrentPages();
			var currPage = pages[pages.length - 1]; //当前页面
			var prevPage = pages[pages.length - 2]; //上一个页面
			request({
				url: 'manage/skin/typeAdd',
				method: 'post',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						if(prevPage.route == 'manage/member/file'){
							prevPage.$vm.item.skinType = that.name
						}
						uni.showToast({
							title:'提交成功',
							icon: 'none',
							duration: 2000,
							success() {
								setTimeout(function(){
									uni.navigateBack()
								}, 2000);
							}
						})
					}else{
						uni.showToast({
							title:'提交失败',
							icon: 'none',
							duration: 2000,
						})
						return;
					}
				},
			})
		}
	},
}
</script>
<style>
@import url("../css/member/skinType.css");
</style>